<?php

namespace frontend\modules\shop\controllers;

use Yii;
use frontend\components\Controller;
use common\helpers\ArrayHelper;
use frontend\modules\shop\models\StandardProductUnit;

/**
 * SPU相关接口
 * 
 * @author emhome<emhome@163.com>
 * @since 2.0
 */
class SpuController extends Controller {

    /**
     * 公共访问
     */
    public $closeCheckAuthent = true;

    /**
     * SKU详情
     * @view view.php
     * @return mixed
     */
    public function actionView($id) {
        $product = StandardProductUnit::findOrFail($id);
        $skus = ArrayHelper::toArray($product->goods);

        $initSku = null;
        if (!empty($skus)) {
            $initSku = array_shift($skus);
        }

        return [
            'goodsinfo' => $product,
            'user_id' => $this->uid,
            'goods_id' => $id,
            'initialSku' => $initSku,
        ];
    }

}
